package com.soft.mainsite.module.staticstrategy.staticservice;

import com.soft.mainsite.common.constant.CmsConst;
import com.soft.mainsite.module.web.cms.service.CategoryService;
import com.soft.mainsite.mybatis.model.TCmsCategory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 内容发布页面静态化接口实现
 *
 * @author liupengtao
 * @date 2019/04/29
 */
@Service
public class ContentStaticServiceImpl implements ContentStaticService {

    @Autowired
    private StaticHtmlService staticHtmlService;

    @Autowired
    private CategoryService categoryService;

    /**
     * 静态化新发布的内容
     * @param siteId
     * @param categoryId
     * @param contentId
     * @param tplType 模板类型 移动/pc
     * @param staticType 静态化类型 新增/删除
     */
    @Override
    public void contentStatic(Integer siteId, Long categoryId, Long contentId, String tplType, Integer staticType) throws Exception {

        TCmsCategory category = categoryService.findById(categoryId);

        //是否是主站发布公共栏目
        boolean isPub = category.getIsCommon() && CmsConst.MAIN_SITE_ID.equals(siteId);

        if (CmsConst.ADD_STATIC.equals(staticType)) {
            //非单页静态化内容页
            if (!category.getAlone()) {
                staticHtmlService.content(siteId, categoryId, contentId, tplType, isPub);
            }
        }
        staticHtmlService.category(siteId, categoryId, tplType);

        if (isPub) {
            //静态化公共栏目列表
            staticHtmlService.commonListStatic(siteId, categoryId, contentId, tplType);
        }

        //静态化触发页面
        staticHtmlService.triggerStatic(siteId, categoryId, contentId, tplType, isPub);

    }

    @Override
    public void contentStatic(Integer siteId, Long categoryId, Long contentId, Integer addStatic) throws Exception{
        // this.contentStatic(siteId, categoryId, contentId,CmsConst.TPL_TYPE_MOBILE,CmsConst.ADD_STATIC)
        this.contentStatic(siteId, categoryId, contentId,CmsConst.TPL_TYPE_PC,CmsConst.ADD_STATIC);
    }


}
